<template>
    <div>
        <div>
            <el-button style="margin-bottom:3px" size="mini" type="primary" @click="showUpdateView">修改</el-button>
            <el-button style="margin-bottom:3px" size="mini" type="primary" @click="deleteLog">删除</el-button>
            <el-button style="margin-bottom:3px" size="mini" type="primary" @click="reSendLog">推送(推送勾选的数据)</el-button>
        </div>
        <el-table
            :data="tableData"
            tooltip-effect="dark"
            style="width: 100%"
            @row-click="loadBackData"
            @selection-change="handleSelectionChange"
            border
            height="300" >
            <el-table-column  type="selection" width="55"></el-table-column>
            <el-table-column  type="index" width="55"></el-table-column>
            <el-table-column  prop="msgId"  label="传输标识"  width="180"></el-table-column>
            <el-table-column  prop="issuedType"  label="类型"  width="200"></el-table-column>
            <el-table-column  prop="deliveryPlanCode"  label="交接单号"  width="180"></el-table-column>
            <el-table-column  prop="itemCode"  label="图号"  width="180"></el-table-column>
            <el-table-column  prop="mProductNumber"  label="型号"  width="120"></el-table-column>
            <el-table-column  prop="qualityCode"  label="质量编号"  width="120"></el-table-column>
            <el-table-column  prop="barcode"  label="条码号"  width="120"></el-table-column>
            <el-table-column  prop="bData"  label="传递ERP参数"  width="280" resizable show-overflow-tooltip></el-table-column>
            <el-table-column  prop="issuedTime"  label="发起时间"  width="160" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="retCode"  label="调用结果"  width="120" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="result"  label="调用结果"  width="120" show-overflow-tooltip></el-table-column>
        </el-table>
        <!--分页-->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page.currentPage"
            :page-sizes="page.pageRandom"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next"
            :total="page.total">
        </el-pagination>
        <!--修改日志信息弹出界面-->
        <div>
            <el-dialog title="提示" :visible.sync="dialog.dialogVisible" width="60%" :before-close="handleClose">
                <el-form ref="form" :model="updateForm" label-width="80px">
                    <el-form-item label="消息ID">
                        <el-input size="mini" v-model="updateForm.msgId"></el-input>
                    </el-form-item>
                    <el-form-item label="参数内容">
                        <el-input type="textarea" :rows="5"  v-model="updateForm.bData"></el-input>
                    </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button siz="mini" @click="dialog.dialogVisible = false">取消</el-button>
                    <el-button siz="mini" type="primary" @click="saveUpdateForm">保存</el-button>
                </span>
            </el-dialog>
        </div>
    </div>
</template>
<script>
import request from "@/utils/request.js";
export default {
    name:"ErpSendTable",
    data(){
        return{
            queryParam:{},//查询参数
            page:{
                currentPage:1,
                pageSize:20,
                total:0,
                pageRandom:[20,50,100,500]
            },
            tableData:[],
            selectData:[],
            dialog:{
                dialogVisible:false
            },
            updateForm:{

            }
        }
    },
    methods:{
        handleSizeChange(val){
            this.page.pageSize = val;
            this.$options.methods.query.bind(this)();
        },
        handleCurrentChange(val){
            this.page.currentPage = val;
            this.$options.methods.query.bind(this)();
        },
        query(){//加载表格数据方法
            var that = this;
            request.post("/erpLogRest/querySendErpLog",{"queryParam":this.queryParam,"page":this.page}).then((res)=>{
                console.log("res",res);
                that.page.total = res.data.total;
                that.tableData = res.data.list;
            });
        },
        loadBackData(row){//加载erpBackTable.vue触发事件
            this.$bus.$emit("loadBackTable",row);
        },
        handleSelectionChange(val){
            this.selectData = val;
        },
        showUpdateView(){
            if(this.selectData.length!=1){
                this.$Alert({title:"失败",message:"请选择一条记录",type:"error"})
                return ;
            }
            this.dialog.dialogVisible = true;
            var dialogData = this.selectData[0];
            this.updateForm = dialogData;
        },
        handleClose(done){
            done();
        },
        saveUpdateForm(){
            request.post("/erpLogRest/updateMsg",this.updateForm).then((res)=>{
                console.log(res);
                if(res.data.retCode=="200"){
                    this.$Alert({title:"成功",message:res.data.message,type:"success"})
                }else{
                    this.$Alert({title:"失败",message:res.data.message,type:"error"})
                };
                this.dialog.dialogVisible = false;
            });
        },
        deleteLog(){
            if(this.selectData==0){
                this.$Alert({title:"失败",message:"请勾选要推送的数据",type:"error"})
                return ;
            }
            this.$confirm("此操作将删除勾选的数据，是否继续？",{
                confirmButtonText:"确定",
                cancelButtonText:"取消",
                type:"warning"
            }).then(()=>{
                request.post("/erpLogRest/deleteLog",this.selectData).then((res)=>{
                    console.log(res);
                    if(res.data.retCode=="200"){
                        this.$Alert({title:"成功",message:res.data.message,type:"success"})
                    }else{
                        this.$Alert({title:"失败",message:res.data.message,type:"error"})
                    };
                    this.dialog.dialogVisible = false;
                    this.$options.methods.query.bind(this)();
                });
            }).catch(()=>{
                this.$message({type:"info",message:"取消删除"})
            });
            
        },
        reSendLog(){
            if(this.selectData.length==0){
                this.$Alert({title:"失败",message:"请勾选要推送的数据",type:"error"})
                return ;
            }
            request.post("/erpLogRest/reSendLog",this.selectData).then((res)=>{
                this.$Alert({title:"成功",message:res.data.message,type:"success"})
                this.$options.methods.query.bind(this)();
            });
        }
        

    },
    mounted(){
        this.$options.methods.query.bind(this)();
        var that = this;
        this.$bus.$on("querySendData",function(queryParam){//初始加载表格数据
            that.queryParam = queryParam;
            that.$options.methods.query.bind(that)();
        })
    }
}
</script>